package com.sts.transform.impl;

import com.googlecode.aviator.AviatorEvaluator;
import com.sts.transform.StsTransform;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author lsl
 * @since 2025年07月08日 19:38
 */
public class RuleFilterTransformImpl implements StsTransform<Boolean> {

    private final String rule;

    public RuleFilterTransformImpl(String rule) {
        this.rule = rule;
    }

    @Override
    public Stream<List<String>> transform(Stream<List<String>> dataStream) {
        return dataStream.filter(this::apply);
    }

    @Override
    public Boolean apply(List<String> row) {
        return (Boolean) AviatorEvaluator.execute(rule, Map.of("row", row), true);
    }
}
